package org.ala.tcp_feign_server.context.executor;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import org.ala.tcp_feign_common.exceptions.RemoteInvokeException;


/**
 * 方法执行器
 *
 * @author 骆毅(ala)
 * @date 2024年4月20日
 */
public class TcpFeignServerExecutor {
	
	
	/**
	 * 执行方法的bean
	 */
	protected Object bean;
	/**
	 * 执行的方法
	 */
	protected Method method;
	/**
	 * 方法的url标识
	 */
	protected String url;
	
	
	public TcpFeignServerExecutor(Object bean, Method method, String url) {
		super();
		this.bean = bean;
		this.method = method;
		this.url = url;
	}


	/**
	 * 执行方法
	 * @throws RemoteInvokeException 
	 */
	public Object invoke(Object[] args) throws RemoteInvokeException {
		try {
			return method.invoke(bean, args);
		} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
			throw new RemoteInvokeException(e);
		}
	}


	public Object getBean() {
		return bean;
	}
}
